<?php session_start(); ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--
//  Copyright (C) 2004-2006  Autodesk, Inc.
//
//  This library is free software; you can redistribute it and/or
//  modify it under the terms of version 2.1 of the GNU Lesser
//  General Public License as published by the Free Software Foundation.
//
//  This library is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//  Lesser General Public License for more details.
//
//  You should have received a copy of the GNU Lesser General Public
//  License along with this library; if not, write to the Free Software
//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-->

<?php include ("../config.php");
	  include ("../utils.php");
	  include(ROOT_DIR_CLASES.'/cCliente.php');
	  include(ROOT_DIR_CLASES.'/log.php');
	  
	  $mostrarMarca = $_REQUEST['mapear'];
	  if ($mostrarMarca == '1') {
		$_SESSION['latGeo'] = $_REQUEST['latitud'];
		$_SESSION['lonGeo'] = $_REQUEST['longitud'];
		$_SESSION['scaleGeo'] = $_REQUEST['scale'];
		$_SESSION['nombrePunto'] = $_REQUEST['nombrePunto'];
		$_SESSION['geoId'] = (isset($_SESSION['geoId']) ? $_SESSION['geoId'] + 1 : 0);
	  }
	  $latImput = isset($_SESSION['latGeo']) ? $_SESSION['latGeo'] :"";
	  $lonImput = isset($_SESSION['lonGeo']) ? $_SESSION['lonGeo'] :"";
	  $scaleImput = isset($_SESSION['scaleGeo']) ? $_SESSION['scaleGeo'] : ZOOM_AVL;
	  $nombrePunto = isset($_SESSION['nombrePunto']) ? $_SESSION['nombrePunto'] : "";
	  $sessionId = ($_SERVER['REQUEST_METHOD'] == "POST")? $_POST['SESSION']: $_GET['SESSION'];
?>
  
<link href="<?php echo ESTILO?>/globalStyles.css" rel="stylesheet" type="text/css">
<link href="<?php echo ESTILO?>/otherStyles.css" rel="stylesheet" type="text/css">
<link href="<?php echo ESTILO?>/viewer.css" rel="stylesheet" type="text/css">
<link href="<?php echo ESTILO?>/bykom.css" rel="stylesheet" type="text/css">

<script>
var cargador = parent.parent.frames["taskBar"];
cargador.document.getElementById("busyImg").style.visibility="hidden";

function validate() {
	var longitud = document.getElementById("longitud").value;
	var latitud = document.getElementById("latitud").value;
	var scale = document.getElementById("scale").value;
	if (longitud.length < 1) {
		alert('longitud no puede estar vacio!');
		return false;
	} else if (isNaN(longitud)) {
		alert('Longitud debe ser un numero');
		return false;
	}
	if (latitud.length < 1) {
		alert('latitud no puede estar vacio!');
		return false;
	} else if (isNaN(latitud)) {
		alert('latitud debe ser un numero');
		return false;
	}
	return true;
}
</script>
<html>
	<head>
		<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
		<meta http-equiv="content-script-type" content="text/javascript">
		<meta http-equiv="content-style-type" content="text/css">
		<link href="../globalStyles.css" rel="stylesheet" type="text/css">
		<link href="../otherStyles.css" rel="stylesheet" type="text/css">
		<link href="/mapguide/viewerfiles/viewer.css" rel="stylesheet" type="text/css">
	</head>
	<body class="AppFrame">
		<form name="frmHistoricoAvl">
				<input type="hidden" name="SESSION" value="<?= $sessionId ?>">
				<input type="hidden" name="mapear" id="mapear" value="0">
				<span class="operation">Geo-Posici&oacute;n</span>
					<br>
					<br>
                	<table>
                	<tr>
                		<td>
                			<span class='texto'>Latitud (Y):</span>
                		</td>
                		<td>
                			<input type="text" name="latitud" id="latitud" value="<?=$latImput?>" class="formchico">
                		</td>
                	</tr>
                	<tr>
                		<td>
                			<span class='texto'>Longitud (X):</span>
                		</td>
                		<td>
                			<input type="text" name="longitud" id="longitud" value="<?=$lonImput?>" class="formchico">
                		</td>
                	</tr>
                	<tr>
                		<td>
                			<span class='texto'>Escala:</span>
                		</td>
                		<td>
                			<input type="text" name="scale" id="scale" value="<?=$scaleImput?>" class="formchico" size="6">
                		</td>
                	</tr>
                	<tr>
                		<td>
                		<table>
                		<tr>
                			<td>
                				<input type="checkbox" name="marcarPunto" id="marcarPunto" class="formchico">
                			</td>
                        	<td>  
                            	<span class='texto'>Marcar punto</span>
                        	</td>
                    	</tr>    
                    	</table>
                		</td>
                		<td>
                			<input type="text" name="nombrePunto" id="nombrePunto" value="<?=$nombrePunto?>" class="formchico">
                    	</td>
                	<tr>
                		<td>&nbsp;</td>
                	</tr>
                	<tr>
                		<td>&nbsp;</td>
                		<td colspan="2">
                		   <input type="button" onclick="geoPosicion();" value="Mapeo" align="center">
                		</td>
                	</tr>	
                	</table>
		</form>

	</body>
<script>
function geoPosicion() {
	if (!validate()) return;
	var marca = document.getElementById("marcarPunto").checked;
	var longitud = document.getElementById("longitud").value;
	var latitud = document.getElementById("latitud").value;
	var scale = document.getElementById("scale").value;
	
	if (marca) {
		document.getElementById("mapear").value = '1';
		document.forms[0].action="operation_GeoPosicion.php";
		document.forms[0].target="_self";
		document.forms[0].submit();
	} else {
		
		if (scale == "" || scale == 0) {
			scale = <?=ZOOM_AVL?>;
		}	
		scale = scale*1.0;	
		parent.parent.mapFrame.ZoomToView(longitud, latitud, scale, false);
	}
}

<?php if ($mostrarMarca == '1') {
?> 
		document.getElementById("mapear").value = '0';
	  	var url = "../posiGeoSelect.php";
		document.forms[0].action=url;
		document.forms[0].target="scriptFrame";
		document.forms[0].submit();
<?php 	
	  }
?>
</script>	
</html>
